package com.easthome.controller;

import com.easthome.entiry.MessageConstant;
import com.easthome.entiry.PageResult;
import com.easthome.entiry.QueryPageBean;
import com.easthome.entiry.Result;
import com.easthome.pojo.CheckItem;
import com.easthome.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 检查项请求和响应
 */
@RestController
@RequestMapping("checkItem")
@Controller
public class CheckItemController {
    //注入业务层对象
    @Autowired
    private CheckItemService checkItemService;

    //添加检查项
    @PostMapping("/addCheckItem")
    public Result addCheckItem(@RequestBody CheckItem checkItem) {
        checkItemService.addCheckItem(checkItem);
        //响应页面端
        return new Result(true, MessageConstant.ADD_CHECKITEM_SUCCESS);
    }
    //分页查询，带条件查询
    @PostMapping("/queryCheckItemPage")
    public Result queryCheckItemPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult pageResult = checkItemService.queryCheckItemPage(queryPageBean);
        return new Result(true,MessageConstant.QUERY_CHECKITEM_SUCCESS,pageResult);
    }
    @GetMapping("/queryCheckItemById")
    public Result queryCheckItemById(Integer id) {
        CheckItem checkItem = checkItemService.queryCheckItemById(id);
        return new Result(true,MessageConstant.QUERY_CHECKITEM_SUCCESS,checkItem);
    }
    //根据主键修改检查项目
    @PostMapping("/updateCheckItemById")
    public Result updateCheckItemById(@RequestBody CheckItem checkItem) {
        checkItemService.updateCheckItemById(checkItem);
        return new Result(true,MessageConstant.EDIT_CHECKITEM_SUCCESS);
    }
    @GetMapping("/deleteCheckItem")
    public Result deleteCheckItem(Integer id) {
        checkItemService.deleteCheckItem(id);
        return new Result(true,MessageConstant.DELETE_CHECKITEM_SUCCESS);
    }
}
